﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication5.Models;
namespace WebApplication5.Controllers
{
    public class DefaultController : Controller
    {
        Model1 model = new Model1();
        // GET: Default
        public ActionResult Index()
        {
            var list = model.Task.ToList();
            return View(list);
        }
        public ActionResult Detail(int id)
        {
            Task task = model.Task.FirstOrDefault(p=>p.TaskID==id);
            return View(task);
        }
        [HttpPost]
        public ActionResult Delete(int id)
        {
            Task task = model.Task.FirstOrDefault(p=>p.TaskID==id);
            if (task!=null) {
                model.Task.Remove(task);
                var result = model.SaveChanges() > 0;
                return Json(result);
            }
            return Json(false);
        }
    }
}